package cn.stu.projectsummit.comment.controller;

import cn.stu.projectsummit.base.response.JsonResult;
import cn.stu.projectsummit.comment.pojo.dto.CommentQuery;
import cn.stu.projectsummit.comment.pojo.vo.CommentListVO;
import cn.stu.projectsummit.comment.pojo.vo.CommentVO;
import cn.stu.projectsummit.comment.service.CommentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("v1/comment")
public class CommentController {
    @Autowired
    CommentService commentService;

    @GetMapping("select")
    public JsonResult selectComment(CommentQuery commentQuery){
        log.debug("查询评论:vehicleQuery={}",commentQuery);
        List<CommentVO> listCommentVO = commentService.selectComment(commentQuery);
        return JsonResult.ok(listCommentVO);
    }
    @PostMapping("delete/{commentId}")
    public JsonResult deleteComment(@PathVariable Long commentId){
        log.debug("删除评论信息 commentId={}",commentId);
        commentService.deleteComment(commentId);
        return JsonResult.ok();
    }


    @GetMapping("{blogId}")
    public JsonResult selectCommentList(@PathVariable Long blogId){
        log.debug("查询评论:blogId={}",blogId);
        return JsonResult.ok(commentService.selectCommentList(blogId));
    }
    @PostMapping("save")
    public JsonResult saveComment(CommentVO commentVO){
        log.debug("保存评论:commentVO={}",commentVO);
        commentService.saveComment(commentVO);
        return JsonResult.ok();
    }
}
